local skel = fk.CreateSkill {
  name = "emo__yiquan",
}

Fk:loadTranslationTable{
  ["emo__yiquan"] = "异权",
  [":emo__yiquan"] = "连招技（【杀】+单目标非伤害牌），你可以选择两项：1.你重铸任意张牌；2.你本阶段【杀】次数+2；3.令此牌目标外所有角色依次失去一点体力。",

  ["#emo__yiquan-choice"] = "异权：选择选两项",
  ["emo__yiquan_recast"] = "重铸任意张牌",
  ["emo__yiquan_slash"] = "【杀】次数+2",
  ["emo__yiquan_losehp"] = "%src 外均掉血",
  ["#emo__yiquan-recast"] = "异权：你可以重铸任意张牌",
}

skel:addEffect(fk.CardUseFinished, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
      data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[skel.name]
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local all_choices = { "emo__yiquan_recast", "emo__yiquan_slash" }
    local to
    if data.tos and #data.tos == 1 then
      to = data.tos[1]
      table.insert(all_choices, "emo__yiquan_losehp:" .. to.id )
    end
    local choices = table.simpleClone(all_choices)
    for i = 1, 2 do
      if player.dead then break end
      local choice = room:askToChoice(player, {
        choices = choices, all_choices = all_choices, skill_name = skel.name, prompt = "#emo__yiquan-choice"
      })
      table.removeOne(choices, choice)
      if choice == "emo__yiquan_recast" then
        local cards = room:askToCards(player, {
          min_num = 1, max_num = 9999, skill_name = skel.name, include_equip = true, cancelable = true,
          prompt = "#emo__yiquan-recast"
        })
        if #cards > 0 then
          room:recastCard(cards, player, skel.name)
        end
      elseif choice == "emo__yiquan_slash" then
        room:addPlayerMark(player, MarkEnum.SlashResidue .. "-phase", 2)
      elseif to then
        room:doIndicate(player, room:getOtherPlayers(to, false))
        for _, p in ipairs(room:getOtherPlayers(to)) do
          if not p.dead then
            room:loseHp(p, 1, skel.name)
            room:delay(200)
          end
        end
      end
    end
  end,
})

skel:addEffect(fk.CardUseFinished, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true) and data.tos and #data.tos == 1 and not data.card.is_damage_card
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local use_events = room.logic:getEventsByRule(GameEvent.UseCard, 2, function (e)
      return e.data.from == player
    end, 1)
    if #use_events == 2 and use_events[2].data.card.trueName == "slash" then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[skel.name] = true
    end
  end,
})

return skel
